<?php

require_once($root_path.'include/care_api_classes/class_core.php');

class Queries_data_search extends Core{
	
	/**
	* SQL query
	*/
	var $sql;
		
	/**
	 * Consulta descriptiva de la tabla care_person
	 * donde el nombre, apellido o nat_id contengan al parametro de entrada
	 * @param $searchkey
	 * jl
	 */
	function select_care_person($searchkey){
		$sql = "SELECT DISTINCT p.pid AS \"id_paciente.value\", p.name_last AS \"apellido_1.value\", p.name_2 AS \"apellido_2.value\", p.name_first AS \"name_1.value\", p.name_middle AS \"name_2.value\", p.sex AS \"sex\", p.ethnic_orig AS \"etnia.value\", 0 AS use_frequency FROM care_person p WHERE p.name_first $sql_LIKE '$searchkey%' OR p.name_last $sql_LIKE '$searchkey%' OR p.nat_id_nr $sql_LIKE '$searchkey%'";
		return $sql;		
	}

	/**
	 * Consulta descritiva de la tabla care_person
	 * ordenado por pid, de manera descendente
	 * jl
	 */
	function select_care_person_order(){
		$sql = "SELECT DISTINCT p.pid AS \"id_paciente.value\", p.name_last AS \"apellido_1.value\", p.name_2 AS \"apellido_2.value\", p.name_first AS \"name_1.value\", p.name_middle AS \"name_2.value\", p.sex AS \"sex\", p.ethnic_orig AS \"etnia.value\", 0 AS use_frequency FROM care_person p ORDER BY p.pid DESC";
		return $sql;		
	}

	/**
	 * Consulta de los distintos nombres de la tabla care_interconsulta_grupo_triaje
	 * donde el nombre contenga al paramentro ingresado
	 * @param $searchkey
	 * jl
	 */
	function select_care_interconsulta_grupo($searchkey){
		$sql = "SELECT DISTINCT nombre AS \"nombre.value\" FROM care_interconsulta_grupo_triaje WHERE nombre $sql_LIKE '$searchkey%'";
		return $sql;		
	}
	
	/**
	 * Consulta de los distintos nombres de la tabla care_interconsulta_grupo_triaje
	 * ordenados descendientemente
	 * @param $searchkey
	 * jl
	 */
	function select_care_interconsulta_grupo_order(){
		$sql = "SELECT DISTINCT nombre AS \"nombre.value\" FROM care_interconsulta_grupo_triaje ORDER BY nombre DESC'";
		return $sql;
	}
		
	/**
	 * Consulta de los distintos login_id de la tabla care_users
	 * donde el nombre o el login_id contengan al paramentro ingresado
	 * @param $searchkey
	 * jl
	 */
	function select_login_care_users($searchkey){
		$sql = "SELECT DISTINCT login_id AS \"login_id.value\" FROM care_users WHERE login_id $sql_LIKE '%$searchkey%' or name $sql_LIKE '%$searchkey%' ";
		return $sql;		
	}
	
	/**
	 * Consulta de los distintos login_id de la tabla care_users
	 * ordenados descendientemente
	 * @param $searchkey
	 * jl
	 */	
	function select_login_care_users_order(){
		$sql = "SELECT DISTINCT login_id AS \"login_id.value\" FROM care_users ORDER BY login_id DESC";
		return $sql;		
	}	
}
?>
